import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'global.dart';
import 'model/profile.dart';

class ProfileChangeNotifier extends ChangeNotifier {
  Profile get _profile => Global.profile;
  @override
  void notifyListeners() {
    Global.saveProfile();
    super.notifyListeners();
  }

}

class UserModel extends ProfileChangeNotifier {

}

class ThemeModel extends ProfileChangeNotifier {
  bool get isDark => _profile.isDark!;
  set isDark(bool isDark) {
    _profile.isDark = isDark;
    notifyListeners();
  }

}

class LocaleModel extends ProfileChangeNotifier {
  Locale ? getLocale() {
    if (_profile.locale == null) return null;
    var t = _profile.locale?.split("-");
    return Locale(t![0], t[1]);
  }

  String? get local => _profile.locale;

  set locale(String? local) {
    if (local != _profile.locale) {
      _profile.locale;
      notifyListeners();
    }
  }
}